
package hopital.admin;

import hopital.orm.Infirmier;
import hopital.orm.Utilisateur;
import hopital.sql.SqlDatabase;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class InfirmierInterface extends javax.swing.JInternalFrame {

    public InfirmierInterface() {
        initComponents();
        initiallize();
        
    }

    public final void initiallize()
    {
        try {
            List<Object> _list = hopital.sql.SqlDatabase.getDatabase().retrive(new Infirmier());
            list1.removeItems();
            for(Object _doc:_list){
                list1.addItem(_doc);
            }
        } catch (Exception ex) {
            Logger.getLogger(InfirmierInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 
    @SuppressWarnings("unchecked")
    private void initComponents() {//GEN-BEGIN:initComponents

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        list1 = new hopital.ui.List();
        _panel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        _nom = new javax.swing.JTextField();
        _prenom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        _email = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        _telephone = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        _adresse = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        _status = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        _add = new javax.swing.JButton();
        _modify = new javax.swing.JButton();
        _delete = new javax.swing.JButton();

        setFrameIcon(null);

        jPanel2.setLayout(new java.awt.BorderLayout());

        list1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                list1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(list1);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jSplitPane1.setLeftComponent(jPanel2);

        jLabel1.setText("Nom");

        jLabel2.setText("Prenom");

        jLabel3.setText("Email");

        jLabel4.setText("Adresse");

        _adresse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _adresseActionPerformed(evt);
            }
        });

        jLabel5.setText("Telephone");

        _status.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout _panelLayout = new javax.swing.GroupLayout(_panel);
        _panel.setLayout(_panelLayout);
        _panelLayout.setHorizontalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_panelLayout.createSequentialGroup()
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(_panelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(_status, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, _panelLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(_panelLayout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_telephone, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(_panelLayout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_email, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(_panelLayout.createSequentialGroup()
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(_prenom, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(_panelLayout.createSequentialGroup()
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(_nom, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(_panelLayout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(_adresse, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(140, Short.MAX_VALUE))
        );
        _panelLayout.setVerticalGroup(
            _panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_panelLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(_panelLayout.createSequentialGroup()
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(_nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(_prenom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(_telephone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_adresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(32, 32, 32)
                .addComponent(_status, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane1.setRightComponent(_panel);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        _add.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/plus25.png"))); // NOI18N
        _add.setText("Nouveau");
        _add.setFocusable(false);
        _add.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _add.setMaximumSize(new java.awt.Dimension(100, 100));
        _add.setMinimumSize(new java.awt.Dimension(100, 100));
        _add.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _addActionPerformed(evt);
            }
        });
        jToolBar1.add(_add);

        _modify.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/font2.png"))); // NOI18N
        _modify.setText("Editer");
        _modify.setFocusable(false);
        _modify.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _modify.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _modify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _modifyActionPerformed(evt);
            }
        });
        jToolBar1.add(_modify);

        _delete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/remove11.png"))); // NOI18N
        _delete.setText("Supprimer");
        _delete.setFocusable(false);
        _delete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        _delete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        _delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _deleteActionPerformed(evt);
            }
        });
        jToolBar1.add(_delete);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        pack();
    }//GEN-END:initComponents

    private void list1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_list1ValueChanged
        if (list1.getSelectedValue()!=null) {
            Utilisateur _user = (Utilisateur) list1.getSelectedValue();
            _nom.setText(_user.getNom());
            _prenom.setText(_user.getPrenom());
            _adresse.setText(_user.getAdresse());
            _email.setText(_user.getEmail());
            _telephone.setText(_user.getTelephone());
        }
    }//GEN-LAST:event_list1ValueChanged

    private void _adresseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__adresseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__adresseActionPerformed

    private void _addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__addActionPerformed
        try {
            Dialog dialog = new Dialog(null, new Infirmier());
            initiallize();
        } catch (Exception e) {
        }
            
    }//GEN-LAST:event__addActionPerformed

    private void _modifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__modifyActionPerformed
       if (list1.getSelectedValue()!=null) {
           try {
               Utilisateur _user = (Utilisateur) list1.getSelectedValue();
               Dialog dialog = new Dialog(null, _user);
               initiallize();
           } catch (Exception ex) {
               Logger.getLogger(InfirmierInterface.class.getName()).log(Level.SEVERE, null, ex);
           }
        }
    }//GEN-LAST:event__modifyActionPerformed

    private void _deleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__deleteActionPerformed
        if (list1.getSelectedValue()!=null) {
           try {
               Utilisateur _user = (Utilisateur) list1.getSelectedValue();
               SqlDatabase.getDatabase().destroy(_user);
               initiallize();
           } catch (Exception ex) {
               Logger.getLogger(InfirmierInterface.class.getName()).log(Level.SEVERE, null, ex);
           }
        }
    }//GEN-LAST:event__deleteActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _add;
    private javax.swing.JTextField _adresse;
    private javax.swing.JButton _delete;
    private javax.swing.JTextField _email;
    private javax.swing.JButton _modify;
    private javax.swing.JTextField _nom;
    protected javax.swing.JPanel _panel;
    private javax.swing.JTextField _prenom;
    private javax.swing.JLabel _status;
    private javax.swing.JTextField _telephone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private hopital.ui.List list1;
    // End of variables declaration//GEN-END:variables
}
